package com.industrial.operation.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import cn.hutool.core.date.DateTime;
import cn.hutool.core.date.DateUtil;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.industrial.common.log.annotation.Log;
import com.industrial.common.log.enums.BusinessType;
import com.industrial.common.security.annotation.RequiresPermissions;
import com.industrial.operation.domain.OperationEconomicIndicators;
import com.industrial.operation.service.IOperationEconomicIndicatorsService;
import com.industrial.common.core.web.controller.BaseController;
import com.industrial.common.core.web.domain.AjaxResult;
import com.industrial.common.core.utils.poi.ExcelUtil;
import com.industrial.common.core.web.page.TableDataInfo;

/**
 * 重点企业运行（按市）Controller
 * 
 * @author Zhou_S
 * @date 2024-01-18
 */
@RestController
@RequestMapping("/indicators")
public class OperationEconomicIndicatorsController extends BaseController
{
    @Autowired
    private IOperationEconomicIndicatorsService operationEconomicIndicatorsService;

    /**
     * 查询重点企业运行（按市）列表
     */
    @RequiresPermissions("operation:indicators:list")
    @GetMapping("/list")
    public TableDataInfo list(OperationEconomicIndicators operationEconomicIndicators)
    {
        if(StringUtils.isNotBlank(operationEconomicIndicators.getYearMonth()) && operationEconomicIndicators.getYearMonth().length() == 4){

        }else{
            if(StringUtils.isNotBlank(operationEconomicIndicators.getYearMonth())){
                String yearMohth=operationEconomicIndicators.getYearMonth()+"-01";
                operationEconomicIndicators.setYearMonth(yearMohth);
            }
        }
        startPage();
        List<OperationEconomicIndicators> list = operationEconomicIndicatorsService.selectOperationEconomicIndicatorsList(operationEconomicIndicators);
        return getDataTable(list);

    }

    /**
     * 导出重点企业运行（按市）列表
     */
    @RequiresPermissions("operation:indicators:export")
    @Log(title = "重点企业运行（按市）", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, OperationEconomicIndicators operationEconomicIndicators)
    {
        List<OperationEconomicIndicators> list = operationEconomicIndicatorsService.selectOperationEconomicIndicatorsList(operationEconomicIndicators);
        ExcelUtil<OperationEconomicIndicators> util = new ExcelUtil<OperationEconomicIndicators>(OperationEconomicIndicators.class);
        util.exportExcel(response, list, "重点企业运行（按市）数据");
    }

    /**
     * 获取重点企业运行（按市）详细信息
     */
    @RequiresPermissions("operation:indicators:query")
    @GetMapping(value = "/{baseId}")
    public AjaxResult getInfo(@PathVariable("baseId") String baseId)
    {
        return success(operationEconomicIndicatorsService.selectOperationEconomicIndicatorsByBaseId(baseId));
    }

    /**
     * 新增重点企业运行（按市）
     */
    @RequiresPermissions("operation:indicators:add")
    @Log(title = "重点企业运行（按市）", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody OperationEconomicIndicators operationEconomicIndicators)
    {
        return toAjax(operationEconomicIndicatorsService.insertOperationEconomicIndicators(operationEconomicIndicators));
    }

    /**
     * 修改重点企业运行（按市）
     */
    @RequiresPermissions("operation:indicators:edit")
    @Log(title = "重点企业运行（按市）", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody OperationEconomicIndicators operationEconomicIndicators)
    {
        return toAjax(operationEconomicIndicatorsService.updateOperationEconomicIndicators(operationEconomicIndicators));
    }

    /**
     * 删除重点企业运行（按市）
     */
    @RequiresPermissions("operation:indicators:remove")
    @Log(title = "重点企业运行（按市）", businessType = BusinessType.DELETE)
	@DeleteMapping("/{baseIds}")
    public AjaxResult remove(@PathVariable String[] baseIds)
    {
        return toAjax(operationEconomicIndicatorsService.deleteOperationEconomicIndicatorsByBaseIds(baseIds));
    }


}
